package com.xb.system.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class RabbitMQConfig {

    public static final String FILE_QUEUE = "fileQueue";
    public static final String FILE_EXCHANGE = "fileExchange";
    public static final String FILE_ROUTING_KEY = "fileRoutingKey";

    @Bean
    public Queue fileQueue() {
        log.info("创建RabbitMQ队列: {}", FILE_QUEUE);
        return new Queue(FILE_QUEUE, true); // true 表示队列是持久化的
    }
    
    @Bean
    public DirectExchange fileExchange() {
        log.info("创建RabbitMQ交换机: {}", FILE_EXCHANGE);
        return new DirectExchange(FILE_EXCHANGE, true, false);
    }
    
    @Bean
    public Binding fileBinding() {
        log.info("创建RabbitMQ绑定: {} -> {} (routingKey: {})", FILE_QUEUE, FILE_EXCHANGE, FILE_ROUTING_KEY);
        return BindingBuilder.bind(fileQueue()).to(fileExchange()).with(FILE_ROUTING_KEY);
    }
}
